package cn.iocoder.yudao.module.system.controller.admin.erp.warehouseoutsuk;
import cn.iocoder.yudao.module.system.controller.admin.erp.warehouseoutsuk.vo.WarehouseOutSukPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.erp.warehouseoutsuk.vo.WarehouseOutSukRespVO;
import cn.iocoder.yudao.module.system.controller.admin.erp.warehouseoutsuk.vo.WarehouseOutSukSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.erp.warehouseoutsuk.WarehouseOutSukDO;
import cn.iocoder.yudao.module.system.service.erp.warehouseoutsuk.WarehouseOutSukService;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.*;
import jakarta.servlet.http.*;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

@Tag(name = "管理后台 - 出库单sku")
@RestController
@RequestMapping("/erp/warehouse-out-suk")
@Validated
public class WarehouseOutSukController {

    @Resource
    private WarehouseOutSukService warehouseOutSukService;

    @PostMapping("/create")
    @Operation(summary = "创建出库单sku")
    @PreAuthorize("@ss.hasPermission('erp:warehouse-out-suk:create')")
    public CommonResult<Long> createWarehouseOutSuk(@Valid @RequestBody WarehouseOutSukSaveReqVO createReqVO) {
        return success(warehouseOutSukService.createWarehouseOutSuk(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新出库单sku")
    @PreAuthorize("@ss.hasPermission('erp:warehouse-out-suk:update')")
    public CommonResult<Boolean> updateWarehouseOutSuk(@Valid @RequestBody WarehouseOutSukSaveReqVO updateReqVO) {
        warehouseOutSukService.updateWarehouseOutSuk(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除出库单sku")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('erp:warehouse-out-suk:delete')")
    public CommonResult<Boolean> deleteWarehouseOutSuk(@RequestParam("id") Long id) {
        warehouseOutSukService.deleteWarehouseOutSuk(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得出库单sku")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('erp:warehouse-out-suk:query')")
    public CommonResult<WarehouseOutSukRespVO> getWarehouseOutSuk(@RequestParam("id") Long id) {
        WarehouseOutSukDO warehouseOutSuk = warehouseOutSukService.getWarehouseOutSuk(id);
        return success(BeanUtils.toBean(warehouseOutSuk, WarehouseOutSukRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得出库单sku分页")
    @PreAuthorize("@ss.hasPermission('erp:warehouse-out-suk:query')")
    public CommonResult<PageResult<WarehouseOutSukRespVO>> getWarehouseOutSukPage(@Valid WarehouseOutSukPageReqVO pageReqVO) {
        PageResult<WarehouseOutSukDO> pageResult = warehouseOutSukService.getWarehouseOutSukPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, WarehouseOutSukRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出出库单sku Excel")
    @PreAuthorize("@ss.hasPermission('erp:warehouse-out-suk:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportWarehouseOutSukExcel(@Valid WarehouseOutSukPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<WarehouseOutSukDO> list = warehouseOutSukService.getWarehouseOutSukPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "出库单sku.xls", "数据", WarehouseOutSukRespVO.class,
                        BeanUtils.toBean(list, WarehouseOutSukRespVO.class));
    }

}